import requests
import random
from ddddocr import DdddOcr
from util.ip import get_proxies_poll,get_proxies
proxies = get_proxies()
while True:
    res_login_get = requests.get(f'https://www.labnetwork.com.cn/gateway/basic/mall/oauth/code?{random.random()}', proxies=proxies)

    print(res_login_get.json())

    res_img = res_login_get.json()['data']['img']
    res_uuid = res_login_get.json()['data']['uuid']
    print(res_img[22:], res_uuid)

    ocr = DdddOcr(show_ad=False)
    code = ocr.classification(res_img[22:])
    print(code)

    res_login_post = requests.post(f'https://www.labnetwork.com.cn/gateway/basic/mall/oauth/login', json={
        'userEmail': '335801501@qq.com',
        'password': 'Fan030311',
        'captchaCode': f'{code}',
        "captchaKey": f"{res_uuid}"
    }, proxies=proxies)
    if "验证码错误" in res_login_post.text:
        print(f"验证码识别错误")
    else:
        token = res_login_post.json()['data']['userInfo']['token']

        break


print(token)


res_t = requests.post(f'https://www.labnetwork.com.cn/gateway/oldapi/mall/chemical/products', json={
    "query":"",
    "country":"CN",
    "pageSize":10,
    "chemIds":[],
    "suppliers":[],
    "rank":0,
    "packSize":"",
    "packUnit":"",
    "unitStock":"",
    "selectedUnit":"",
    "molecularWeightLow":"",
    "molecularWeightHigh":"",
    "locations":[],
    "startRecord":0
},headers = {
    "token":token
}, proxies=proxies)
print(res_t.json())